package com.workflow.server.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.sun.org.apache.bcel.internal.generic.IRETURN;
import com.workflow.server.common.Result;
import com.workflow.server.dto.*;
import com.workflow.server.dto.json.ChildNode;
import com.workflow.server.dto.json.FormOperates;
import com.workflow.server.dto.json.SettingsInfo;
import com.workflow.server.dto.json.UserInfo;
import com.workflow.server.entity.ProcessTemplates;
import com.workflow.server.entity.Users;

import com.workflow.server.exception.ProcessValidationException;
import com.workflow.server.service.ProcessTemplateService;
import com.workflow.server.service.UserService;

import com.workflow.server.service.WorkspaceProcessService;
import com.workflow.server.utils.SpringContextHolder;
import com.workflow.server.vo.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.history.HistoricVariableInstance;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.workflow.server.common.CommonConstants.*;
import static com.workflow.server.common.WorkFlowConstants.PROCESS_PREFIX;


/**
 * @author : willian fu
 * @version : 1.0
 */
@RestController
@RequestMapping("/workspace")
@Api(tags = {"Vue2版本 的数据列表,待办,已办,我发起等接口"})
@ApiSort(3)
public class WorkspaceProcessController {
    @Resource
    private ProcessTemplateService processTemplateService;
    @Resource
    private RepositoryService repositoryService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    WorkspaceProcessService workflowService;
    @Resource
    HistoryService historyService;
    @Autowired
    TaskService taskService;
    @ApiOperation("通过模板id查看流程信息 会附带流程定义id")
    @ApiOperationSupport(order = 1)
    @ApiParam(required = true, name = "模板id", value = "该值从form/groupps接口 里面去取")
    @GetMapping("process/detail")
    public Result<ProcessTemplates> detail(@RequestParam("templateId") String templateId) {
        ProcessTemplates processTemplates = processTemplateService.getById(templateId);
        processTemplates.setLogo(processTemplates.getIcon());
        processTemplates.setFormId(processTemplates.getTemplateId());
        processTemplates.setFormName(processTemplates.getTemplateName());
        String processDefKey = PROCESS_PREFIX + templateId;
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey(processDefKey)
                .latestVersion()
                .singleResult();
        if (processDefinition == null) {
            throw new ProcessValidationException("该流程暂未接入Camunda,请重试");
        }
        processTemplates.setProcessDefinitionId(processDefinition.getId());
        return Result.OK(processTemplates);
    }


    @ApiOperationSupport(order = 2)
    @ApiOperation("通过流程定义id启动流程")
    @PostMapping("process/start")
    @Transactional
    public Result<Object> start(@RequestBody StartProcessInstanceDTO startProcessInstanceDTO) {
        JSONObject formData = startProcessInstanceDTO.getFormData();
        UserInfo startUserInfo = startProcessInstanceDTO.getStartUserInfo();
        Map<String, Object> processVariables = new HashMap<>();
        processVariables.put(FORM_VAR, formData);
        processVariables.put(PROCESS_STATUS, BUSINESS_STATUS_1);
        processVariables.put(START_USER_INFO, startUserInfo.getId());
        workflowService.saveFormData(formData);
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(
                startProcessInstanceDTO.getProcessDefinitionId(), processVariables);
        String processInstanceId = processInstance.getId();
        Task task = taskService.createTaskQuery()
                .processInstanceId(processInstanceId)
                .active()
                .singleResult();
        //自动完成发起人节点
        if ("发起人".equals(task.getName())){
            taskService.complete(task.getId());
        }


        return Result.OK(processInstance.getId());

    }


    @ApiOperation("查看我发起的流程")
    @ApiOperationSupport(order = 3)
    @PostMapping("process/applyList")
    public Result<Page<HistoryProcessInstanceVO>> applyList(@RequestBody ApplyDTO applyDTO) {
//        return null;
        List<HistoricProcessInstance> historicProcessInstances =historyService.createHistoricProcessInstanceQuery()
                .startedBy(applyDTO.getCurrentUserInfo().getId())
                .orderByProcessInstanceStartTime()
                .desc()
                .listPage((applyDTO.getPageNo() - 1) * applyDTO.getPageSize(), applyDTO.getPageSize());

//                historyService.createHistoricProcessInstanceQuery()
//                .includeProcessVariables()
//                .startedBy(applyDTO.getCurrentUserInfo().getId())
//                .orderByProcessInstanceStartTime().desc()
//                .listPage((applyDTO.getPageNo() - 1) * applyDTO.getPageSize(), applyDTO.getPageSize());
        long count = historyService.createHistoricProcessInstanceQuery()
                .startedBy(applyDTO.getCurrentUserInfo().getId()).count();
        List<String> applyUserIds= new ArrayList<>();
//        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
//            List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery()
//                    .processInstanceId(historicProcessInstance.getRootProcessInstanceId())
//                    .list();
//            list.stream().map(HistoricVariableInstance::getName)
//            String id = JSONObject.parseObject(MapUtil.getStr(processVariables, START_USER_INFO), new TypeReference<UserInfo>() {
//            }).getId();
//            applyUserIds.add(id);
//        }
//        Map<Long, Users> collect=new HashMap<>();
//        if(CollUtil.isNotEmpty(applyUserIds)){
//            LambdaQueryWrapper<Users> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//            lambdaQueryWrapper.in(Users::getUserId,applyUserIds);
//            List<Users> list = userService.list(lambdaQueryWrapper);
//            collect = list.stream().collect(Collectors.toMap(Users::getUserId, Function.identity()));
//        }

        List<HistoryProcessInstanceVO> historyProcessInstanceVOS= new ArrayList<>();
        Page<HistoryProcessInstanceVO> page=new Page<>();
        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
//            Map<String, Object> processVariables = historicProcessInstance.getProcessVariables();
            HistoryProcessInstanceVO historyProcessInstanceVO=new HistoryProcessInstanceVO();
            historyProcessInstanceVO.setProcessInstanceId(historicProcessInstance.getId());
            historyProcessInstanceVO.setProcessDefinitionName(historicProcessInstance.getProcessDefinitionName());
//            historyProcessInstanceVO.setStartUser(JSONObject.parseObject(MapUtil.getStr(processVariables,START_USER_INFO),new TypeReference<UserInfo>(){}));
//            historyProcessInstanceVO.setUsers(collect.get(Long.valueOf(historyProcessInstanceVO.getStartUser().getId())));
            historyProcessInstanceVO.setStartTime(historicProcessInstance.getStartTime());
            historyProcessInstanceVO.setEndTime(historicProcessInstance.getEndTime());
            Boolean flag= historicProcessInstance.getEndTime() != null;
//            historyProcessInstanceVO.setCurrentActivityName(getCurrentName(historicProcessInstance.getId(),flag,historicProcessInstance.getProcessDefinitionId()));
//            historyProcessInstanceVO.setBusinessStatus(MapUtil.getStr(processVariables,PROCESS_STATUS));


            long totalTimes = historicProcessInstance.getEndTime()==null?
                    (Calendar.getInstance().getTimeInMillis()-historicProcessInstance.getStartTime().getTime()):
                    (historicProcessInstance.getEndTime().getTime()-historicProcessInstance.getStartTime().getTime());
            long dayCount = totalTimes /(1000*60*60*24);//计算天
            long restTimes = totalTimes %(1000*60*60*24);//剩下的时间用于计于小时
            long hourCount = restTimes/(1000*60*60);//小时
            restTimes = restTimes % (1000*60*60);
            long minuteCount = restTimes / (1000*60);

            String spendTimes = dayCount+"天"+hourCount+"小时"+minuteCount+"分";
            historyProcessInstanceVO.setDuration(spendTimes);
            historyProcessInstanceVOS.add(historyProcessInstanceVO);
        }
        page.setRecords(historyProcessInstanceVOS);
        page.setCurrent(applyDTO.getPageNo());
        page.setSize(applyDTO.getPageSize());
        page.setTotal(count);
        return Result.OK(page);
    }


    private String getCurrentName(String processInstanceId, Boolean flag, String processDefinitionId) {
        return null;
//        if(flag){
//            return "流程已结束";
//        }
//        List<ActivityInstance> list = runtimeService.createActivityInstanceQuery().processInstanceId(processInstanceId).activityType("userTask").unfinished().orderByActivityInstanceStartTime().desc().list();
//        if(CollUtil.isEmpty(list)){
//            return "";
//        }
//        else{
//            String activityId = list.get(0).getActivityId();
//            BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
//            FlowElement flowElement = bpmnModel.getMainProcess().getFlowElement(activityId);
//            return flowElement.getName();
//        }
    }

    @ApiOperation("查看我的待办")
    @PostMapping("process/toDoList")
    public Result<Page<TaskVO>> toDoList(@RequestBody TaskDTO taskDTO) {
        return null;
//        List<Task> tasks = taskService.createTaskQuery().taskAssignee(taskDTO.getCurrentUserInfo().getId())
//                .includeProcessVariables()
//                .orderByTaskCreateTime().desc()
//                .listPage((taskDTO.getPageNo() - 1) * taskDTO.getPageSize(), taskDTO.getPageSize());
//        long count = taskService.createTaskQuery().taskAssignee(taskDTO.getCurrentUserInfo().getId()).count();
//        List<TaskVO> taskVOS= new ArrayList<>();
//        Page<TaskVO> page =new Page<>();
//
//
//        List<String> taskIds= new ArrayList<>();
//        for (Task task : tasks) {
//            Map<String, Object> processVariables = task.getProcessVariables();
//            String id = JSONObject.parseObject(MapUtil.getStr(processVariables, START_USER_INFO), new TypeReference<UserInfo>() {
//            }).getId();
//            taskIds.add(id);
//        }
//
//
//        Map<Long, Users> collect=new HashMap<>();
//        if(CollUtil.isNotEmpty(taskIds)){
//            LambdaQueryWrapper<Users> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//            lambdaQueryWrapper.in(Users::getUserId,taskIds);
//            List<Users> list = userService.list(lambdaQueryWrapper);
//            collect = list.stream().collect(Collectors.toMap(Users::getUserId, Function.identity()));
//        }
//
//        for (Task task : tasks) {
//            ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
//            BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
//            Map<String, Object> processVariables = task.getProcessVariables();
//            TaskVO taskVO=new TaskVO();
//            taskVO.setTaskId(task.getId());
//            taskVO.setProcessInstanceId(task.getProcessInstanceId());
//            taskVO.setProcessDefinitionName(bpmnModel.getMainProcess().getName());
//            taskVO.setStartUser(JSONObject.parseObject(MapUtil.getStr(processVariables,START_USER_INFO),new TypeReference<UserInfo>(){}));
//            taskVO.setUsers(collect.get(Long.valueOf(taskVO.getStartUser().getId())));
//            taskVO.setStartTime(processInstance.getStartTime());
//            taskVO.setCurrentActivityName(getCurrentName(processInstance.getId(),false,processInstance.getProcessDefinitionId()));
//
//            taskVO.setBusinessStatus(MapUtil.getStr(processVariables,PROCESS_STATUS));
//            taskVO.setTaskCreatedTime(task.getCreateTime());
//            DelegationState delegationState = task.getDelegationState();
//            if(delegationState!=null){
//                taskVO.setDelegationState(delegationState);
//            }
//            taskVOS.add(taskVO);
//
//        }
//        page.setRecords(taskVOS);
//        page.setCurrent(taskDTO.getPageNo());
//        page.setSize(taskDTO.getPageSize());
//        page.setTotal(count);
//        return Result.OK(page);
    }

    @ApiOperation("查看我的已办")
    @PostMapping("process/doneList")
    public Result<Page<TaskVO>> doneList(@RequestBody TaskDTO taskDTO) {
        return null;
    }

    @ApiOperation("同意按钮")
    @PostMapping("/agree")
    public Result agree(@RequestBody HandleDataDTO handleDataDTO, MultipartFile file) {
        return null;
    }

    @ApiOperation("委派按钮")
    @PostMapping("/delegateTask")
    public Result delegateTask(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }

    @ApiOperation("委派人完成的按钮")
    @PostMapping("/resolveTask")
    public Result resolveTask(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }


    @ApiOperation("拒绝按钮")
    @PostMapping("/refuse")
    public Result refuse(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }

    @ApiOperation("撤销按钮")
    @PostMapping("/revoke")
    public Result revoke(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }


    @ApiOperation("转办按钮")
    @PostMapping("/assignee")
    public Result assignee(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }


    @ApiOperation("退回按钮")
    @PostMapping("/rollback")
    public Result rollback(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }


    @ApiOperation("加签按钮")
    @PostMapping("/addMulti")
    public Result addMulti(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }


    @ApiOperation("查到签上的人")
    @PostMapping("/queryMultiUsersInfo")
    public Result<List<MultiVO>> queryMultiUsersInfo(@RequestBody Map<String, Object> map) {
        return null;
    }

    @ApiOperation("减签按钮")
    @PostMapping("/deleteMulti")
    public Result deleteMulti(@RequestBody List<String> executionIds) {
        return null;
    }


    @ApiOperation("评论按钮")
    @PostMapping("/comments")
    public Result comments(@RequestBody HandleDataDTO handleDataDTO) {
        return null;
    }

    @ApiOperation("通过流程实例id查看详情")
    @PostMapping("process/instanceInfo")
    public Result<HandleDataVO> instanceInfo(@RequestBody HandleDataDTO HandleDataDTO) {
        return null;
//        String processInstanceId = HandleDataDTO.getProcessInstanceId();
//        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId)
//                .includeProcessVariables().singleResult();
//        String processDefinitionKey = historicProcessInstance.getProcessDefinitionKey();
//        ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX,""));
//        processTemplates.setLogo(processTemplates.getIcon());
//        processTemplates.setFormId(processTemplates.getTemplateId());
//        processTemplates.setFormName(processTemplates.getTemplateName());
//        processTemplates.setProcessDefinitionId(historicProcessInstance.getProcessDefinitionId());
//
//        HandleDataVO handleDataVO =new HandleDataVO();
//        Map<String, Object> processVariables = historicProcessInstance.getProcessVariables();
//
//        handleDataVO.setProcessInstanceId(historicProcessInstance.getId());
//        JSONObject jsonObject = (JSONObject) processVariables.get(FORM_VAR);
//        handleDataVO.setFormData(jsonObject);
//        String process = processTemplates.getProcess();
//        ChildNode childNode = JSONObject.parseObject(process, new TypeReference<ChildNode>(){});
//        SettingsInfo settingsInfo = JSONObject.parseObject(processTemplates.getSettings(), new TypeReference<SettingsInfo>() {});
//        Boolean sign = settingsInfo.getSign();
//        ChildNode currentNode=null;
//        if(StringUtils.isNotBlank(HandleDataDTO.getTaskId())){
//            HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(HandleDataDTO.getTaskId()).singleResult();
//            currentNode = getChildNode(childNode, historicTaskInstance.getTaskDefinitionKey());
//            List<FormOperates> formPerms = currentNode.getProps().getFormPerms();
//            if(CollUtil.isNotEmpty(formPerms)){
//                Iterator<FormOperates> iterator = formPerms.iterator();
//                while (iterator.hasNext()){
//                    FormOperates next = iterator.next();
//                    if("H".equals(next.getPerm())){
//                        iterator.remove();
//                        if(jsonObject!=null){
//                            jsonObject.remove(next.getId());
//                        }
//                    }
//                }
//            }
//            handleDataVO.setCurrentNode(currentNode);
//            handleDataVO.setTaskId(HandleDataDTO.getTaskId());
//        }
//
//        if(sign){
//            handleDataVO.setSignFlag(true);
//        }
//        if(StringUtils.isNotBlank(HandleDataDTO.getTaskId())){
//            if(currentNode!=null){
//                if(currentNode.getProps().getSign()){
//                    handleDataVO.setSignFlag(true);
//                }
//                else{
//                    handleDataVO.setSignFlag(false);
//                }
//            }
//        }
//
//
//
//
//        List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).list();
//        Map<String,List<HistoricActivityInstance>> historicActivityInstanceMap =new HashMap<>();
//        for (HistoricActivityInstance historicActivityInstance : list) {
//            List<HistoricActivityInstance> historicActivityInstances = historicActivityInstanceMap.get(historicActivityInstance.getActivityId());
//            if(historicActivityInstances==null){
//             historicActivityInstances =new ArrayList<>();
//             historicActivityInstances.add(historicActivityInstance);
//             historicActivityInstanceMap.put(historicActivityInstance.getActivityId(),historicActivityInstances);
//            }
//            else{
//                historicActivityInstances.add(historicActivityInstance);
//                historicActivityInstanceMap.put(historicActivityInstance.getActivityId(),historicActivityInstances);
//            }
//        }
//
//        Process mainProcess = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId()).getMainProcess();
//        Collection<FlowElement> flowElements = mainProcess.getFlowElements();
//
//        List<String> runningList= new ArrayList<>();
//        handleDataVO.setRunningList(runningList);
//        List<String> endList=new ArrayList<>();
//        handleDataVO.setEndList(endList);
//        List<String> noTakeList=new ArrayList<>();
//        handleDataVO.setNoTakeList(noTakeList);
//        Map<String,List<TaskDetailVO>> deatailMap =new HashMap<>();
//        List<Comment> processInstanceComments = taskService.getProcessInstanceComments(historicProcessInstance.getId());
//        List<Attachment> processInstanceAttachments = taskService.getProcessInstanceAttachments(historicProcessInstance.getId());
//        for (FlowElement flowElement : flowElements) {
//            List<TaskDetailVO> detailVOList =new ArrayList<>();
//            List<HistoricActivityInstance> historicActivityInstanceList = historicActivityInstanceMap.get(flowElement.getId());
//            if(CollUtil.isNotEmpty(historicActivityInstanceList)){
//                for (HistoricActivityInstance historicActivityInstance : historicActivityInstanceList) {
//                    if(historicActivityInstance.getEndTime()!=null){
//                        if("startEvent".equalsIgnoreCase(historicActivityInstance.getActivityType()) ||"endEvent".equalsIgnoreCase(historicActivityInstance.getActivityType())){
//                            TaskDetailVO taskDetailVO = new TaskDetailVO();
//                            taskDetailVO.setActivityId(historicActivityInstance.getActivityId());
//                            taskDetailVO.setName(historicActivityInstance.getActivityName());
//                            taskDetailVO.setCreateTime(historicActivityInstance.getStartTime());
//                            taskDetailVO.setEndTime(historicActivityInstance.getEndTime());
//                            detailVOList.add(taskDetailVO);
//                            deatailMap.put(historicActivityInstance.getActivityId(),detailVOList);
//                            endList.add(historicActivityInstance.getActivityId());
//                        }
//                        else if ("userTask".equalsIgnoreCase(historicActivityInstance.getActivityType())){
//                            List<TaskDetailVO> voList = deatailMap.get(historicActivityInstance.getActivityId());
//                            List<HistoricActivityInstance> activityInstanceList = list.stream().filter(h -> h.getActivityId().equals(historicActivityInstance.getActivityId()) &&h.getEndTime()!=null).collect(Collectors.toList());
//                            if(voList!=null){
//                                collectUserTaskInfo(processInstanceComments, processInstanceAttachments, historicActivityInstance, voList, activityInstanceList);
//                            }
//                            else{
//                                voList=new ArrayList<>();
//                                collectUserTaskInfo(processInstanceComments, processInstanceAttachments, historicActivityInstance, voList, activityInstanceList);
//                            }
//                            deatailMap.put(historicActivityInstance.getActivityId(),voList);
//                            endList.add(historicActivityInstance.getActivityId());
//                        }
//                        else if("serviceTask".equalsIgnoreCase(historicActivityInstance.getActivityType())){
//
//                        }
//                    }
//                    else{
//                        if ("userTask".equalsIgnoreCase(historicActivityInstance.getActivityType())){
//                            List<TaskDetailVO> voList = deatailMap.get(historicActivityInstance.getActivityId());
//                            List<HistoricActivityInstance> activityInstanceList = list.stream().filter(h -> h.getActivityId().equals(historicActivityInstance.getActivityId()) &&h.getEndTime()==null).collect(Collectors.toList());
//                            if(voList!=null){
//                                collectUserTaskInfo(processInstanceComments, processInstanceAttachments, historicActivityInstance, voList, activityInstanceList);
//                            }
//                            else{
//                                voList=new ArrayList<>();
//                                collectUserTaskInfo(processInstanceComments, processInstanceAttachments, historicActivityInstance, voList, activityInstanceList);
//                            }
//                            deatailMap.put(historicActivityInstance.getActivityId(),voList);
//                            if(endList.contains(historicActivityInstance.getActivityId())){
//                                endList.remove(historicActivityInstance.getActivityId());
//                                runningList.add(historicActivityInstance.getActivityId());
//                            }
//                            else{
//                                runningList.add(historicActivityInstance.getActivityId());
//                            }
//                        }
//                        else if("serviceTask".equalsIgnoreCase(historicActivityInstance.getActivityType())){
//
//                        }
//                    }
//                }
//            }
//            else{
//                noTakeList.add(flowElement.getId());
//            }
//        }
//        handleDataVO.setProcessTemplates(processTemplates);
//        handleDataVO.setDetailVOList(deatailMap);
//        return Result.OK(handleDataVO);
    }


    @ApiOperation("上传文件")
    @PostMapping("upLoadFile")
    public Result<AttachmentVO> upLoadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        return null;

//        MinioUploadUtil minioUploadUtil = SpringContextHolder.getBean(MinioUploadUtil.class);
//        MinioClient minioClient = SpringContextHolder.getBean(MinioClient.class);
//        AttachmentVO attachmentVO= new AttachmentVO();
//        attachmentVO.setName(file.getOriginalFilename());
//        minioUploadUtil.uploadFile(file, "java", file.getOriginalFilename());
//        try {
//            String url = minioClient.getPresignedObjectUrl(
//                    GetPresignedObjectUrlArgs.builder()
//                            .bucket("java")
//                            .object(file.getOriginalFilename())
//                            .expiry(7, TimeUnit.DAYS) // 设置5秒的超时时间。
//                            .method(Method.GET)
//                            .build());
//            attachmentVO.setUrl(url);
//        } catch (ErrorResponseException e) {
//            e.printStackTrace();
//        } catch (InsufficientDataException e) {
//            e.printStackTrace();
//        } catch (InternalException e) {
//            e.printStackTrace();
//        } catch (InvalidKeyException e) {
//            e.printStackTrace();
//        } catch (InvalidResponseException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//        } catch (XmlParserException e) {
//            e.printStackTrace();
//        } catch (ServerException e) {
//            e.printStackTrace();
//        }
//        return Result.OK(attachmentVO);
    }

    @ApiOperation("下载文件")
    @PostMapping("downLoadFile")
    public void downLoadFile(@RequestParam("name") String name) {

    }

}
